home *** CD-ROM | disk | FTP | other *** search
/ APDL Eductation Resources / APDL Eductation Resources.iso / programs / electronic / rlab / TestMatrix / vand_r < prev    next >
Encoding:
Text File  |  1994-12-20  |  1.3 KB  |  57 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. // Synopsis:    Vandermonde matrix.
  4.  
  5. // Syntax:    V = vand ( P )
  6. //        V = vand ( M , P )
  7.  
  8. // Descriptioin:
  9.  
  10. //    V = vand(P), where P is a vector, produces the (primal)
  11. //    Vandermonde matrix based on the points P, i.e. 
  12. //    V[i;j] = P[j]^(i-1). 
  13.  
  14. //      vand ( M , P ) is a rectangular version of VAND(P) with M
  15. //    rows. Special case: If P is a scalar then P equally spaced
  16. //    points on [0,1] are used.
  17.  
  18. //      Reference:
  19. //      N.J. Higham, Stability analysis of algorithms for solving
  20. //      confluent Vandermonde-like systems, SIAM J. Matrix Anal. Appl.,
  21. //      11 (1990), pp. 23-41.
  22.  
  23. //    This file is a translation of vand.m from version 2.0 of
  24. //    "The Test Matrix Toolbox for Matlab", described in Numerical
  25. //    Analysis Report No. 237, December 1993, by N. J. Higham.
  26.  
  27. // Dependencies
  28.    require seqa
  29.  
  30. //-------------------------------------------------------------------//
  31.  
  32. vand = function ( m , p )
  33. {
  34.   local (m, p)
  35.  
  36.   if (!exist (p)) { p = m; narg = 1; else narg = 2; }
  37.   n = max(size(p));
  38.  
  39.   //  Handle scalar p.
  40.   if (n == 1)
  41.   {
  42.     n = p;
  43.     p = seqa(0,1,n);
  44.   }
  45.  
  46.   if (narg == 1) { m = n; }
  47.  
  48.   p = p[:].';        // Ensure p is a row vector.
  49.   V = ones(m,n);
  50.   for (i in 2:m)
  51.   {
  52.     V[i;] = p.*V[i-1;];
  53.   }
  54.  
  55.   return V;
  56. };
  57.